import matplotlib.pyplot as plt
import numpy as np
def f(x,g):
    return 0.5*(x[0]**2+g*x[1]**2)
gamma = 0.1
x0 = np.array([gamma,1])
epsilon = 1e-4
plt.figure(figsize=(8,8))
plt.subplot(221)
while f(x0,gamma)>epsilon:
    x1 = x0 * (gamma-1)/(gamma+1)
    x1[1] = -x1[1]
    plt.plot([x0[0],x1[0]],[x0[1],x1[1]])
    x0 = x1
plt.title("gamma = 0.1")

gamma = 10
x0 = np.array([gamma,1])
plt.subplot(222)
while f(x0,gamma)>epsilon:
    x1 = x0 * (gamma-1)/(gamma+1)
    x1[1] = -x1[1]
    plt.plot([x0[0],x1[0]],[x0[1],x1[1]])
    x0 = x1
plt.title("gamma = 10")

gamma = 0.5
x0 = np.array([gamma,1])
plt.subplot(223)
while f(x0,gamma)>epsilon:
    x1 = x0 * (gamma-1)/(gamma+1)
    x1[1] = -x1[1]
    plt.plot([x0[0],x1[0]],[x0[1],x1[1]])
    x0 = x1
plt.title("gamma = 0.5")

gamma = 2
x0 = np.array([gamma,1])
plt.subplot(224)
while f(x0,gamma)>epsilon:
    x1 = x0 * (gamma-1)/(gamma+1)
    x1[1] = -x1[1]
    plt.plot([x0[0],x1[0]],[x0[1],x1[1]])
    x0 = x1
plt.title("gamma = 2")

plt.show()

